package com.parking.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.parking.common.dao.impl.BaseDaoImpl;
import com.parking.dao.IShareParkingDao;
import com.parking.entity.Parking;
import com.parking.entity.ShareParking;

@Repository("shareParkingDao")
public class ShareParkingDaoImpl extends BaseDaoImpl<ShareParking, Integer> implements IShareParkingDao{

	private static Logger logger = Logger.getLogger(ShareParkingDaoImpl.class);
	
	@Override
	public List<ShareParking> findByKeywordAndAreacode(String keyword, int areacode, int pageSize,
			int pageNum, int type) {
		String hql = "from ShareParking as shareParking where shareParking.name like :keyword and shareParking.areacode = :areacode and shareParking.type = :type order by shareParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		params.put("type", type);
		return find(hql, params, pageSize, pageNum);
	}

	@Override
	public List<ShareParking> findByKeywordAndAreacode(String keyword, int areacode, int type) {
		String hql = "from ShareParking as shareParking where shareParking.name like :keyword and shareParking.areacode = :areacode and shareParking.type = :type order by shareParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		params.put("type", type);
		return find(hql, params);
	}

	@Override
	public long countByKeywordAndAreacode(String keyword, int areacode, int type) {
		String hql = "select count(*) from ShareParking as shareParking where shareParking.name like :keyword and shareParking.areacode = :areacode and shareParking.type = :type order by shareParking.id desc";
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("keyword", "%" + keyword + "%");
		params.put("areacode", areacode);
		params.put("type", type);
		return countAll(hql, params);
	}

}
